package com.party.admin.biz.datacount;

import com.party.core.model.activity.Activity;
import com.party.core.model.order.OrderType;
import com.party.core.service.activity.IActivityService;
import com.party.core.service.order.IOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 数据统计业务接口
 * Created by wei.li.
 *
 * @date 2017/12/20 0020
 * @time 18:44
 */

@Service
public class DataCountBizService {

    @Autowired
    private IActivityService activityService;

    @Autowired
    private IOrderFormService orderFormService;


    /**
     * 初始化数据
     */
    public void init(){
        List<Activity> list = activityService.list(new Activity());
        for (Activity activity : list){
            int joinNum
                    = orderFormService.calculateBuyNum(activity.getId(),
                    null, false, OrderType.ORDER_ACTIVITY.getCode());
            activity.setJoinNum(joinNum);
            activityService.update(activity);
        }
    /*    List<DataCount> list = dataCountService.list(new DataCount());
        for (DataCount dataCount : list){

            Activity activity = activityService.get(dataCount.getTargetId());
            if (null != activity){
                activity.setReadNum(dataCount.getViewNum());
                activity.setSalesNum(dataCount.getSalesNum());
                activity.setShareNum(dataCount.getShareNum());
                activity.setSalesAmount(dataCount.getSalesAmount());
                activityService.update(activity);
                continue;
            }

            Project project = projectService.get(dataCount.getTargetId());
            if (null != project){
                project.setViewNum(dataCount.getViewNum());
                projectService.update(project);
                continue;
            }

            Article article = articleService.get(dataCount.getTargetId());
            if (null != activity){
                article.setReadNum(dataCount.getViewNum());
                article.setShareNum(dataCount.getShareNum());
                articleService.update(article);
                continue;
            }

            Goods goods = goodsService.get(dataCount.getTargetId());
            if (null != goods){
                goods.setViewNum(dataCount.getViewNum());
                goods.setShareNum(dataCount.getShareNum());
                goods.setShareNum(dataCount.getShareNum());
                goods.setSalesAmount(dataCount.getSalesAmount());
                goodsService.update(goods);
                continue;
            }
        }*/
    }
}
